var path = require('path')
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const productionGzipExtensions = ['js', 'css']
const env = process.env.NODE_ENV

module.exports = {
  lintOnSave: false,
  devServer: {
    port: 8082,
    proxy: {
      '/api': {
        target: process.env.VUE_APP_PROXY_TARGET, // 目标代理接口地址
        secure: false,
        changeOrigin: true, // 开启代理，在本地创建一个虚拟服务端
        pathRewrite: {
          '^/api': '/api',
        },
      },
    },
  },
  pages: {
    index: {
      entry: 'src/main.js',
      title: 'easyadmin-front', //放要改的title名
    },
  },
  chainWebpack: (config) => {
    config.resolve.alias.set('@', path.resolve(__dirname, 'src')),
      config.module
        .rule('md')
        .test(/\.md/)
        .use('text-loader')
        .loader('text-loader')
        .end()
    /*  .use('vue-markdown-loader')
        .loader('vue-markdown-loader/lib/markdown-compiler')
        .options({
          raw: true,
        }) */
  },
  configureWebpack: (config) => {
    if (env === 'prod') {
      ;(config.externals = {
        // 不会被打包的库
        Vue: 'Vue',
        'element-ui': 'ELEMENT',
        Vuex: 'Vuex',
        moment: 'moment',
        echarts: 'echarts',
        'vue-router': 'VueRouter',
        axios: 'axios',
      }),
        config.plugins.push(
          new CompressionWebpackPlugin({
            algorithm: 'gzip',
            test: new RegExp(`\\.(${productionGzipExtensions.join('|')})$`),
            threshold: 10240,
            minRatio: 0.8,
            deleteOriginalAssets: false,
          })
        )
    }
  },
}
